Fix module fixtures with --doctest-modules#14540
Conversation
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
this is a good start and a fix
please expand the docs on the test
@bluetech a later major followup could make dedicated fs nodes part of the collection tree and specific nodes could decide if they ancor fixtures in the file node or the specific node
this first idea needs more iteration
| reprec = pytester.inline_run(p, "--doctest-modules") | ||
| reprec.assertoutcome(passed=1) | ||
|
|
||
| def test_module_fixture_available_to_normal_test_with_doctestmodules( |
There was a problem hiding this comment.
please add a mark that links the issue and add a note on the regression on the docstring
eeed18e to
0ae2a23
Compare
|
Thanks, updated the regression test docs for the DoctestModule/Module fixture case. CI is green now. |
|
If we key The PR should document in the changelog the fact that higher-scoped autouse fixtures will now execute twice when using If we impart to users the mental model that
Interesting idea, but regarding the "specific nodes could decide if they ancor fixtures in the file node or the specific node" part:
|
0ae2a23 to
c70b02a
Compare
pytest can collect the same Python module through DoctestModule and Module. FixtureManager skipped the second parse because it keyed parsed holders only by module object. Key parsed holders by visibility anchor too. Normal tests get FixtureDefs anchored to their Module collector, and node-based fixture scoping remains unchanged. Closes pytest-dev#14533. Co-authored-by: OpenAI Codex <codex@openai.com>
c70b02a to
0526d9b
Compare
|
Updated per feedback: removed CI is green now. |
|
@bluetech hence the need for iteration - theres need for certain cooperation to make things work nice technically i would actually go as far as considering doctestmodules a collector that intently is actually a child of the module, that it is at the same level as the module its "contained in" is the real issue for me |
Summary
--doctest-modulescollects a Python module before the normal module collector.FixtureDefs without relaxing node-based scoping.Closes #14533.
Test plan
PYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/test_doctest.py::TestDoctests::test_module_fixture_available_to_normal_test_with_doctestmodules testing/test_doctest.py::TestDoctests::test_doctestmodule_with_fixtures testing/test_doctest.py::TestDoctests::test_doctestmodule_three_tests testing/test_doctest.py::TestDoctestAutoUseFixtures—37 passed in 0.75sPYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/test_conftest.py::test_conftest_fixture_scoping_with_testpaths_outside_rootdir testing/test_conftest.py::test_conftest_fixture_from_ancestor_above_rootdir testing/deprecated_test.py::TestFixtureNodeidDeprecations—6 passed in 0.14sPYTHONPATH=src python /tmp/pytest-14533-repro/run_checkout_pytest.py -q testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_conftest testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_conftest_and_module_and_class testing/python/fixtures.py::TestFixtureManagerParseFactories::test_parsefactories_relative_node_ids—3 passed in 0.10sgit diff --checkpython -m compileall -q src/_pytest/fixtures.py testing/test_doctest.pypython -m ruff check src/_pytest/fixtures.py testing/test_doctest.pypython -m ruff format --check src/_pytest/fixtures.py testing/test_doctest.pyAI assistance
OpenAI Codex helped reproduce the bug, draft the regression test, and prepare the initial patch. I reviewed the diff, checked the fixture scoping risk, added the changelog and AUTHORS entries, reran the targeted tests, and take responsibility for the change.
closes #14533to the PR description and commit message.Co-authored-bycommit trailer.changelog/.AUTHORSin alphabetical order.